
import {OrbitControls} from "@react-three/drei";
import {Perf} from "r3f-perf";
import {CuboidCollider,Debug,RigidBody,Physics} from "@react-three/rapier";
import {useRef} from "react";


export default function Demo7(){
    const box=useRef<any>()
    const clickBox=()=>{
        box.current.applyImpulse({x:-5,y:0,z:0})
    }
    return(
        <>
            <Perf position='top-left' />
            {/*控制屏幕移动放大缩小*/}
            <OrbitControls makeDefault/>

            <directionalLight position={[1,2,3]} intensity={1.5}/>
            <ambientLight intensity={0.5}/>

            <Physics>
                <Debug />
                <RigidBody colliders='ball'>
                    <mesh castShadow position={[0,4,0]}>
                        <sphereGeometry />
                        <meshStandardMaterial color='orange'/>
                    </mesh>
                </RigidBody>
                <RigidBody ref={box}>
                    {/*<mesh castShadow position={[2,2,0]}>*/}
                    {/*    <boxGeometry args={[3,2,1]}/>*/}
                    {/*    <meshStandardMaterial color='mediumpurple' />*/}
                    {/*</mesh>*/}
                    <mesh onClick={clickBox} castShadow position={[2,2,0]}>
                        <boxGeometry args={[1,1,1]} />
                        <meshStandardMaterial color='mediumpurple' />
                    </mesh>
                </RigidBody>
                {/*<RigidBody colliders={'trimesh'}>*/}
                {/*    <CuboidCollider args={[1,1,1]}/>*/}
                {/*    <mesh castShadow position={[0,1,0]} rotation={[Math.PI*0.5,0,0]}>*/}
                {/*        <torusGeometry args={[1,0.5,16,32]}/>*/}
                {/*        <meshStandardMaterial color='mediumpurple' />*/}
                {/*    </mesh>*/}
                {/*</RigidBody>*/}
                <RigidBody type='fixed'>
                    <mesh receiveShadow position-y={-1.25}>
                        <boxGeometry  args={[10,0.5,10]}/>
                        <meshStandardMaterial color='greenyellow' />
                    </mesh>
                </RigidBody>
            </Physics>
        </>
    )
}
